﻿using System.Text;

namespace RemoteSensingImageDirectServer.Untils.Tool
{
    public static class RSIFileTool
    {
        /// <summary>
        /// 将文件转为二进制流
        /// </summary>
        /// <param name="filename">文件路径</param>
        /// <returns>文件的二进制流</returns>
        public static byte[] FileToByteArray(string filename)
        {
            using (FileStream myStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                var buffer = new byte[myStream.Length];
                var br = new BinaryReader(myStream, Encoding.ASCII);
                br.Read(buffer, 0, buffer.Length);
                myStream.Close();
                return buffer;
            }
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="filename">文件路径</param>
        public static void Delete(string filename)
        {
            if (File.Exists(filename)) 
            {
                File.Delete(filename);
            }
        }
    }
}
